package com.yan.demo.method;

import java.util.Arrays;
import java.util.Random;

public class MethodTest1 {
    public static void main(String[] args) {
        int[] arr = new int[5];
        Random r = new Random();
        for (int i = 0; i < arr.length; i++) {
            arr[i] = r.nextInt(99) + 1;
        }
        int num = getScore(arr);
        System.out.println("大于平均值的个数为" + num);
    }

    public static int getScore(int[] arr){
        int num = 0;
        double sum = 0.0;
         double avg = 0.0;
        for (int i = 0; i < arr.length; i++) {
            sum += arr[i];
        }
        avg = sum / arr.length;
        for (int i = 0; i < arr.length; i++) {
            if(arr[i] >= avg){
                num++;
            }
        }
        System.out.println(Arrays.toString(arr));
        return num;
    }
}
